#include "delay.h"

uint32_t Delay_Counter = 0;

static  uint32_t TimingDelay ;

void Delay( uint32_t nTime)
{
  TimingDelay = nTime;

  while(TimingDelay != 0)
  {
	  TimingDelay --;
  }
}


void TimingDelay_Decrement(void)
{
  if (TimingDelay != 0x00)
  {
    TimingDelay--;
  }
}




/* delay for msec */
void Delay_ms (uint32_t  time)
{

	/* Assign value to the global counter */
	Delay_Counter = time;

	/* Set up Systick timer with 1/1000th sec period */
    SysTick_Config(SystemCoreClock/1000);

    while (Delay_Counter > 0);

    return;
}

void Delay_us (uint32_t  time)
{

	/* Assign value to the global counter */
	Delay_Counter = time;

	/* Set up Systick timer with 1/1000th sec period */
    SysTick_Config(SystemCoreClock/1000000);

    while (Delay_Counter > 0);

    return;
}

void SysTick_Handler(void)
{
	Delay_Counter--;

	return;
}
